import {Space, message, Divider} from 'antd';
import { CSSProperties } from 'react';
import { Link, useModel } from 'umi';
import Avatar from './AvatarDropdown';
import NoticeIcon from './NoticeIcon/NoticeIcon';

import { isNil } from 'lodash';

import styles from './index.less';
import {history} from "@@/core/history";

const Nav = ({ children, style }: { children?: any; style?: CSSProperties }) => {
    const { initialState } = useModel('@@initialState');
    const isLogin: boolean = !isNil(initialState?.currentUser);
    const { query = {},pathname} = history.location;
    const { redirect } = query as { redirect: string };
    if (!initialState || !initialState.settings) {
        return null;
    }

    return (
        <div className={styles.wrapper} style={{ ...style }}>
            <Space split={<Divider type="vertical" />}>
                {children}
                {isLogin && (
                    <>
                        <NoticeIcon
                            count={10}
                            onItemClick={(item: any) => {
                                message.info(`${item.title} 被点击了`);
                            }}
                            onClear={(title: string, key: string) => message.info('点击了清空更多')}
                            loading={false}
                            clearText="清空"
                            viewMoreText="查看更多"
                            onViewMore={() => message.info('点击了查看更多')}
                            clearClose
                        >
                            <NoticeIcon.Tab
                                tabKey="notification"
                                count={2}
                                list={[]}
                                title="通知"
                                emptyText="你已查看所有通知"
                                showViewMore
                            />
                            <NoticeIcon.Tab
                                tabKey="message"
                                count={2}
                                list={[]}
                                title="消息"
                                emptyText="您已读完所有消息"
                                showViewMore
                            />
                            <NoticeIcon.Tab
                                tabKey="event"
                                title="待办"
                                emptyText="你已完成所有待办"
                                count={2}
                                list={[]}
                                showViewMore
                            />
                        </NoticeIcon>
                        <Avatar />
                    </>
                )}
                {!isLogin &&
                    // <Button type="link" size="small">
                    //     登录
                    // </Button>
                    <Link to={`/user/login?redirect=${redirect||pathname}`}>登录</Link>
                }
            </Space>
        </div>
    );
};
export default Nav;
